package com.xmall.service.impl;

import com.xmall.bean.vo.*;
import com.xmall.mapper.OrderGoodsMapper;
import com.xmall.mapper.OrderMapper;
import com.xmall.mapper.UserMapper;
import com.xmall.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Connor
 * @ClassName: StatServiceImpl
<<<<<<< HEAD:src/main/java/com/xmall/service/impl/StatServiceImpl.java
 * @PackageName: com.xmall.service.impl
=======
 * @PackageName: com.xmall.service.admin
 * @Description: TODO
>>>>>>> lzshun:src/main/java/com/xmall/service/admin/StatServiceImpl.java
 * @date 2020/12/06
 * @Version 1.0
 */
@Service
public class StatServiceImpl implements StatService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    OrderGoodsMapper orderGoodsMapper;

    @Override
    public StatisticalReportVO<RowsUserVO> queryUserData() {
        List<String> columnNameList = new ArrayList<>();
        columnNameList.add("day");
        columnNameList.add("users");
        List<RowsUserVO> rowsUserVOList = userMapper.countUsersByAddTime();

        return new StatisticalReportVO<>(columnNameList, rowsUserVOList);
    }

    @Override
    public StatisticalReportVO<RowsOrderVO> queryOrderData() {
        List<String> columnNameList = new ArrayList<>();
        columnNameList.add("day");
        columnNameList.add("orders");
        columnNameList.add("customers");
        columnNameList.add("amount");
        columnNameList.add("pcr");
        List<RowsOrderVO> rowsOrderVOList = orderMapper.queryOrderData();

        return new StatisticalReportVO<>(columnNameList,rowsOrderVOList );
    }

    @Override
    public StatisticalReportVO<RowsGoodsVO> queryGoodsData() {
        ArrayList<String> columnNameList = new ArrayList<>();
        columnNameList.add("day");
        columnNameList.add("orders");
        columnNameList.add("products");
        columnNameList.add("amount");
        List<RowsGoodsVO> rowsGoodsVOList = orderMapper.queryGoodsDataByAddTime();
        List<RowsGoodsTempVO> rowsGoodsTempVOList = orderGoodsMapper.countProductsByAddTime();
        for (RowsGoodsTempVO rowsGoodsTempVO : rowsGoodsTempVOList) {
            for (RowsGoodsVO rowsGoodsVO : rowsGoodsVOList) {
                if (rowsGoodsTempVO.getDay().equals(rowsGoodsVO.getDay())) {
                    rowsGoodsVO.setProducts(rowsGoodsTempVO.getProducts());
                }
            }
        }

        return  new StatisticalReportVO<>(columnNameList, rowsGoodsVOList);
    }
}
